<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 180px;"
        class="filter-item"
        placeholder="请输入交易号"
        v-model="queryForm.voucherCode"
      >
      </el-input>
      <el-input
        style="width: 180px;"
        class="filter-item"
        placeholder="请输入用户手机号"
        v-model="queryForm.phone"
      >
      </el-input>
      <el-button
        class="filter-item"
        @click="doQuery"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      @sort-change="handleSortChange"
      :data="records"
      style="width: 100%"
    >
      <el-table-column prop="rowId" label="ID" width="100" align="center">
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="用户昵称"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="phone" label="手机号" width="150" align="center">
      </el-table-column>
      <el-table-column
        prop="voucherCode"
        label="交易号"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="transCode"
        label="交易类型"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          {{ Dicts.TRANS_CODE[scope.row.transCode] }}
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeAmount"
        label="交易金额"
        width="200"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="changeDir"
        label="进账/出账"
        width="200"
        align="center"
      >
        <template slot-scope="scope">
          {{ Dicts.CHANGE_DIR[scope.row.changeDir] }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="交易时间"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        class-name="small-padding"
        width="200"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-permission="'acctountBook:detail'"
            size="mini"
            type="default"
            @click="handleQueryById(scope.row, 'published')"
            icon="el-icon-search"
            circle
            title="查看详情"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>

    <!-- 详情弹出框 -->
    <el-dialog
      :title="`账户交易详情`"
      :visible.sync="dialogShowFormVisible"
      width="50%"
    >
      <el-form :model="showForm" label-width="120px" ref="showForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户名称:" prop="realName">
              {{ showForm.realName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号:" prop="phone">
              {{ showForm.phone }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账户号:" prop="acctNo">
              {{ showForm.acctNo }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业务单号:" prop="voucherCode">
              {{ showForm.voucherCode }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账户原金额:" prop="originAmount">
              {{ showForm.originAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="交易金额:" prop="tradeAmount">
              {{ showForm.tradeAmount }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当前账户余额:" prop="presentAmount">
              {{ showForm.presentAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="改变方向:" prop="changeDir">
              <template slot-scope="scope">
                {{ Dicts.CHANGE_DIR[showForm.changeDir] }}
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易说明:" prop="tradeDesc">
              {{ showForm.tradeDesc }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="交易类型名:" prop="transName">
              {{ showForm.transName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易开始时间:" prop="createTime">
              {{ showForm.createTime }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogShowFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryAccountBook, queryIntrAcctBookDetailByRowId } from '@/api/account'

export default {
  name: 'accountBook',
  data() {
    return {
      loading: false,
      dialogShowFormVisible: false,
      showForm: [],
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        importance: undefined,
        title: undefined
      },
      transCodeOptions: Dicts.TRANS_CODE,
      records: []
    }
  },
  created() {
    this.doQuery()
  },
  methods: {
    handleSortChange({ column, prop, order }) {
      this.queryForm.ascs = ''
      this.queryForm.descs = ''
      if (order) {
        if (order === 'ascending') {
          this.queryForm.ascs = column.sortBy
        } else {
          this.queryForm.descs = column.sortBy
        }
      }
      this.queryForm.current = 0
      this.doQuery()
    },
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      queryAccountBook(this.queryForm).then(({ data: { data } }) => {
        this.queryForm.current = data.current
        this.queryForm.pages = data.pages
        this.queryForm.total = data.total
        this.queryForm.size = data.size
        this.records = data.records
        this.loading = false
      })
    },
    handleQueryById({ rowId }) {
      queryIntrAcctBookDetailByRowId(rowId).then(
        ({ data: { code, data, msg } }) => {
          if (code === 0) {
            this.openShowDialog()
            this.showForm = data
          }
        }
      )
    },
    openShowDialog() {
      this.showForm = {}
      this.dialogShowFormVisible = true
      this.$refs.showForm && this.$refs.showForm.resetFields()
    }
  },
  components: {}
}
</script>

<style scoped></style>
